PROJECT_PATH = ..

SUB_PROJECT = $(PROJECT_PATH)/tools/inih

OUT_PATH := out

TARGET := cli

# target source
AR = ar
CC = gcc
CXX = g++


LIBS_DIR += -L./
# 依赖的库文件
LIBS += -lpthread

CFLAGS += -g -w

### 头文件路径
INC_DIR :=
INC_DIR += -I$(PROJECT_PATH)/
INC_DIR += -I$(PROJECT_PATH)/inc/
INC_DIR += -I$(PROJECT_PATH)/tools/

CFLAGS += $(LIBS_DIR) $(INC_DIR)

### 子项目依赖

LIB_STATIC += $(SUB_PROJECT)/out/inih.a


#### 源码路径
MAIN_FILE := qiandisk-cli.cpp

SRC_CPP_DIR := $(PROJECT_PATH)/src

OBJ_DIR := $(OUT_PATH)

SRC_CPP_FILES := $(wildcard $(SRC_CPP_DIR)/*.cpp)
# $(info $(SRC_CPP_FILES))

### 目标文件
OBJ := $(patsubst $(SRC_CPP_DIR)/%.cpp,$(OBJ_DIR)/%.o, $(SRC_CPP_FILES))
# $(info $(OBJ_CPP))


OBJ_MAIN := $(patsubst %.cpp,$(OBJ_DIR)/%.o, $(MAIN_FILE))

$(info $(OBJ_MAIN))

all: $(TARGET)


$(TARGET): $(OBJ)  $(OBJ_MAIN) $(LIB_STATIC)
	$(CXX) -o $@ $^ $(CFLAGS)

## 各个cpp的目标文件
$(OBJ_DIR)/%.o: $(SRC_CPP_DIR)/%.cpp
	$(CXX) -c $< -o $@ $(CFLAGS)

$(OBJ_MAIN): $(MAIN_FILE)
	$(CXX) -c $^ -o $@  $(CFLAGS)



.PHONY:clean
clean:
	rm $(OUT_PATH)/*
	rm $(TARGET)


